package dev.ideas.funkyj.function;

/**
 */
public abstract class P<X> extends F<X, Boolean> {
    @Deprecated /*better use a named function*/ protected P() { }
    protected P(String string) { super(string); }

    @Override abstract public Boolean apply(X x);

    public P<X> and(final P<X> p) {
        return new P<X>(this + " and " + p) {
            public Boolean apply(X x) { return P.this.apply(x) && p.apply(x); }
        };
    }
    public P<X> or(final P<X> p) {
        return new P<X>(this + " or (" + p + ")") {
            public Boolean apply(X x) { return P.this.apply(x) || p.apply(x); }
        };
    }
    public P<X> not() {
        return new P<X>("not (" + this + ")") {
            public Boolean apply(X x) { return !P.this.apply(x); }
        };
    }

    //todo bad name!
    public <X1> P2<X, X1> with(final P<X1> p1) {
        return new P2<X, X1>() {
            @Override public boolean apply(X x, X1 x1) {
                return P.this.apply(x) && p1.apply(x1);
            }
        };
    }
}
